<style>
.layui-form-pane .layui-form-label{width:auto;}
.layui-form-item{margin-bottom: 0px;}
</style>
<div class="fixed-bar">
<form class="layui-form layui-form-pane fixed-bar-form" action="{:url()}" method="get" id="hisi-table-search">
<div class="layui-form-item">
 
 <div class="layui-inline">
 	<label class="layui-form-label">物料名称</label>
     <div class="layui-input-inline">
         <input type="text" name="name" lay-verify="" placeholder="输入物料名称" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">物料SKU</label>
     <div class="layui-input-inline">
         <input type="text" name="material_sku" lay-verify="" placeholder="输入物料SKU" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">内部SKU</label>
     <div class="layui-input-inline">
         <input type="text" name="self_sku" lay-verify="" placeholder="输入内部SKU" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">颜色</label>
     <div class="layui-input-inline">
         <input type="text" name="color" lay-verify="" placeholder="输入物料颜色" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">订单号</label>
     <div class="layui-input-inline">
         <input type="text" name="client_ordernum" lay-verify="" placeholder="输入订单号" class="layui-input">
     </div>
 </div>
    {if env('env_site') == 'riwei' }
    <div class="layui-inline">
        <label class="layui-form-label">客户单号</label>
        <div class="layui-input-inline">
            <input type="text" name="ext_id" lay-verify="" placeholder="输入客户单号" class="layui-input">
        </div>
    </div>
    {/if}
 
 <div class="layui-inline">
 	<label class="layui-form-label">产品SKU</label>
     <div class="layui-input-inline">
         <input type="text" name="sku" lay-verify="" placeholder="输入产品SKU" class="layui-input">
     </div>
 </div>
 <div class="layui-inline">
 	<label class="layui-form-label">供应商</label>
     <div class="layui-input-inline">
         <input type="text" name="supplier" lay-verify="" placeholder="输入供应商" class="layui-input">
     </div>
 </div>
  <div class="layui-inline">
    <label class="layui-form-label">物料类型</label>
    <div class="layui-input-inline">
        <input type="hidden" name="material_property_v2" value="0">
        {:Form::select('material_type', '', [''=> '全部', 1=>'面料', 2=>'铺料'], 'material_property_select', '',' lay-filter="material_property_select"')}
    </div>
</div>
 <div class="layui-inline">
 	<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">搜索</button>
 </div>
</div>
</form>
</div>

<table id="dataTable"></table>

{include file="system@block/layui" /}

<script type="text/html" id="toolbar">
    <div class="">
        <a href="{:url('add')}" class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-circle-fine hisi-iframe" hisi-data="{width: '500px', height: '500px'}" title="添加物料">&nbsp;添加</a>
		<a data-href="{:url('setCheckcloth')}" data-table="dataTable" class="layui-btn layui-btn-primary layui-btn-sm confirm layui-icon layui-icon-search green hisi-table-ajax">&nbsp;设置为需验布</a>
		<a data-href="{:url('setShrink')}" data-table="dataTable" class="layui-btn layui-btn-primary layui-btn-sm confirm layui-icon layui-icon-set-sm blue hisi-table-ajax">&nbsp;设置为需缩水</a>
		<a data-href="{:url('checkOddments')}?val=2" onclick="openCheckoutWindow1()" class="layui-btn layui-btn-sm layui-bg-blue">合并物料</a>
    </div>
</script>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
	<a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs hisi-iframe" hisi-data="{width: '730px', height: '500px'}" title="修改物料">修改</a>
    <a href="{:url('StockNew/addMaterialCheckIn')}?material_sku={{ d.material_sku }}&materialid={{d.id}}" class="layui-btn layui-btn-xs layui-btn-warm hisi-iframe" hisi-data="{width: '710px', height: '400px'}" title="物料入库">物料入库</a>
</script>
<script type="text/html" id="useOrders">
    {{ d.use_orders_30d }} / 
	{{# if(d.use_orders > 0){ }}
		<a href="{:url('history')}?id={{ d.id }}" class="hisi-iframe blue" title="使用产品记录">{{ d.use_orders }}</a>
	{{# }else{ }}
		0
	{{# } }}
</script>
<script type="text/html" id="useTimeTpl">
    <div>{{layui.util.toDateString(d.use_time * 1000) }}</div>
</script>

<script type="text/javascript">
    layui.use(['table','jquery', 'tool'], function() {
		var $ = layui.jquery;
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,limits: [20,50,100,150,200]
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter', 'exports', 'print']
            ,cols: [[ //表头
            	{type:'checkbox', fixed:'left',field:"material_id"}
                ,{field: 'id', title: '编号',width: 80}
                ,{field: 'name', title: '物料名称',width: 180, templet:function(d){return layui.tool.formatMaterialType(d.type, '', 2)+'<span class="copy-item">'+d.name+'</span>';}}
                ,{field: 'material_sku', title: '物料SKU',width: 150, templet:function(d){return '<span class="copy-item">'+d.material_sku+'</span>';}}
				,{field: 'self_sku', title: '内部SKU',width: 120, templet:function(d){return '<span class="copy-item">'+d.self_sku+'</span>';}}
                ,{field: 'supplier', title: '供应商',width: 100, templet:function(d){return '<span class="copy-item">'+d.supplier+'</span>';}}
                ,{field: 'model', title: '型号',width: 100}
                ,{field: 'colornum', title: '色号',width: 80}
                ,{field: 'color', title: '颜色',width: 80}
                ,{field: 'unit', title: '单位',width: 60}
                ,{field: 'price', title: '单价',width: 80}
                ,{field: 'contact', title: '联系方式',width: 120, templet:function(d){return '<span class="copy-item">'+d.contact+'</span>';}}
                ,{field: 'address', title: '地址',width: 100}
                ,{field: 'need_checkcloth', title: '验布',width: 80, templet:function(d){return layui.tool.formatBool(d.need_checkcloth)}}
                ,{field: 'need_shrink', title: '缩水',width: 80, templet:function(d){return layui.tool.formatBool(d.need_shrink)}}
                ,{field: 'use_orders', title: '常用产品数',width: 100, templet: '#useOrders'}
                ,{field: 'use_time', title: '最近使用时间', templet: '#useTimeTpl',width: 150}
                ,{field: '', title: '操作', templet: '#buttonTpl', fixed: 'right',width: 150}
            ]]
        });
		// 获取某些物料的各厂数据
		window.openCheckoutWindow1 = function(material_id=0,stock_id=0) {
			if($(".layui-form-checked").size()<=0 && material_id==0){
				layer.msg('请选择要操作的数据', {icon: 2,anim: 6});return;
			}
			var checkids='';
			var that = $(document);
			var tableObj = that.attr('data-table') ? that.attr('data-table') : 'dataTable';
			var checkStatus = table.checkStatus(tableObj);
			console.log(checkStatus);
			for(var i=0;i<checkStatus.data.length;i++){
				checkdata=checkStatus.data;
				checkids+=checkdata[i]['id']+',';
			}
			checkids=material_id!=0 ? material_id : checkids; //查询各个物料各厂数据 特别处理
			//data: $('.form-plan').eq(1).serialize(),
			//var content = $('#doneTpl').html();
			var title='物料sku合并-将不同的外部sku但相同物料统一编号内部sku';
			layerStockOutIn = layer.open({
				type: 2
				,area: ['1240px','590px']
				,offset: '50px'
				//,shade:[0.8, '#393D49']
				,anim: parseInt(Math.random()*(6+1),10)
				,skin:'layui-layer-molv'
				,title:title
				,content: "{:url('StockNew/materialMerge')}?mids="+checkids
			});
		}
    });
</script>